import java.util.Arrays;
import java.util.Scanner;

public class Test {


    //数组nums包含从0到n的所有整数，但其中缺了一个。请编写代码找出那个缺失的整数。

    //1.法1
    public static void main1(String[] args) {

        int[] arr=new int[]{3,2,1,0,6,5};
        int sum=0;
        for(int i=0;i<arr.length;i++){
            sum^=i;
            sum^=arr[i];
        }
        sum^=arr.length;
        System.out.println(sum);

    }
//法2
    public static void main2(String[] args) {
        int[] arr={0,3,2,4,5,7,6,1,9};
        int count=0;
        int sum=0;
        int n=arr.length;

        for(int i=0;i<=n;i++){
            sum+=i;
        }
        for(int i=0;i<n;i++){
            count+=arr[i];

        }
        System.out.println(sum-count);
    }


    //2.旋转数字
    //输入: nums = [1,2,3,4,5,6,7], k = 3
    //输出: [5,6,7,1,2,3,4]
    //输入：nums = [-1,-100,3,99], k = 2
    //输出：[3,99,-1,-100]
    public static void main(String[] args) {
        int[] num={1,2,3,5,6,7,8};
        int k=0;
        Scanner cin=new Scanner(System.in);
        System.out.println("输入开始旋转的位置");
        k= cin.nextInt();
        k=k% num.length;

        reverse(num,0, num.length-1);
        System.out.println(Arrays.toString(num));
        reverse(num,0,k-1);
        System.out.println(Arrays.toString(num));
        reverse(num,k, num.length-1);
        System.out.println(Arrays.toString(num));


    }
    public static void reverse(int[] num,int start,int end){
        while(start<end){
            int temp=num[start];
            num[start]=num[end];
            num[end]=temp;
            start++;
            end--;

        }
    }
}
